package cn.shuto.liferay.plugin.chart.service.model.impl;

import cn.shuto.liferay.plugin.chart.service.model.ChartTemplate;
import cn.shuto.liferay.plugin.chart.service.model.ChartTemplateModel;
import cn.shuto.liferay.plugin.chart.service.model.ChartTemplateSoap;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.json.JSON;
import com.liferay.portal.kernel.lar.StagedModelType;
import com.liferay.portal.kernel.util.DateUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.util.PortalUtil;

import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;

import java.io.Serializable;

import java.sql.Types;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * The base model implementation for the ChartTemplate service. Represents a row in the &quot;echarts_ChartTemplate&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link cn.shuto.liferay.plugin.chart.service.model.ChartTemplateModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link ChartTemplateImpl}.
 * </p>
 *
 * @author shixw
 * @see ChartTemplateImpl
 * @see cn.shuto.liferay.plugin.chart.service.model.ChartTemplate
 * @see cn.shuto.liferay.plugin.chart.service.model.ChartTemplateModel
 * @generated
 */
@JSON(strict = true)
public class ChartTemplateModelImpl extends BaseModelImpl<ChartTemplate>
    implements ChartTemplateModel {
    /*
     * NOTE FOR DEVELOPERS:
     *
     * Never modify or reference this class directly. All methods that expect a chart template model instance should use the {@link cn.shuto.liferay.plugin.chart.service.model.ChartTemplate} interface instead.
     */
    public static final String TABLE_NAME = "echarts_ChartTemplate";
    public static final Object[][] TABLE_COLUMNS = {
            { "uuid_", Types.VARCHAR },
            { "chartTemplateId", Types.BIGINT },
            { "groupId", Types.BIGINT },
            { "companyId", Types.BIGINT },
            { "userId", Types.BIGINT },
            { "userName", Types.VARCHAR },
            { "createDate", Types.TIMESTAMP },
            { "modifiedDate", Types.TIMESTAMP },
            { "name", Types.VARCHAR },
            { "description", Types.VARCHAR },
            { "script", Types.CLOB },
            { "templateParam", Types.CLOB }
        };
    public static final String TABLE_SQL_CREATE = "create table echarts_ChartTemplate (uuid_ VARCHAR(75) null,chartTemplateId LONG not null primary key,groupId LONG,companyId LONG,userId LONG,userName VARCHAR(75) null,createDate DATE null,modifiedDate DATE null,name VARCHAR(75) null,description VARCHAR(75) null,script TEXT null,templateParam TEXT null)";
    public static final String TABLE_SQL_DROP = "drop table echarts_ChartTemplate";
    public static final String ORDER_BY_JPQL = " ORDER BY chartTemplate.createDate DESC";
    public static final String ORDER_BY_SQL = " ORDER BY echarts_ChartTemplate.createDate DESC";
    public static final String DATA_SOURCE = "liferayDataSource";
    public static final String SESSION_FACTORY = "liferaySessionFactory";
    public static final String TX_MANAGER = "liferayTransactionManager";
    public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
                "value.object.entity.cache.enabled.cn.shuto.liferay.plugin.chart.service.model.ChartTemplate"),
            true);
    public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
                "value.object.finder.cache.enabled.cn.shuto.liferay.plugin.chart.service.model.ChartTemplate"),
            true);
    public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
                "value.object.column.bitmask.enabled.cn.shuto.liferay.plugin.chart.service.model.ChartTemplate"),
            true);
    public static long COMPANYID_COLUMN_BITMASK = 1L;
    public static long GROUPID_COLUMN_BITMASK = 2L;
    public static long UUID_COLUMN_BITMASK = 4L;
    public static long CREATEDATE_COLUMN_BITMASK = 8L;
    public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
                "lock.expiration.time.cn.shuto.liferay.plugin.chart.service.model.ChartTemplate"));
    private static ClassLoader _classLoader = ChartTemplate.class.getClassLoader();
    private static Class<?>[] _escapedModelInterfaces = new Class[] {
            ChartTemplate.class
        };
    private String _uuid;
    private String _originalUuid;
    private long _chartTemplateId;
    private long _groupId;
    private long _originalGroupId;
    private boolean _setOriginalGroupId;
    private long _companyId;
    private long _originalCompanyId;
    private boolean _setOriginalCompanyId;
    private long _userId;
    private String _userUuid;
    private String _userName;
    private Date _createDate;
    private Date _modifiedDate;
    private String _name;
    private String _description;
    private String _script;
    private String _templateParam;
    private long _columnBitmask;
    private ChartTemplate _escapedModel;

    public ChartTemplateModelImpl() {
    }

    /**
     * Converts the soap model instance into a normal model instance.
     *
     * @param soapModel the soap model instance to convert
     * @return the normal model instance
     */
    public static ChartTemplate toModel(ChartTemplateSoap soapModel) {
        if (soapModel == null) {
            return null;
        }

        ChartTemplate model = new ChartTemplateImpl();

        model.setUuid(soapModel.getUuid());
        model.setChartTemplateId(soapModel.getChartTemplateId());
        model.setGroupId(soapModel.getGroupId());
        model.setCompanyId(soapModel.getCompanyId());
        model.setUserId(soapModel.getUserId());
        model.setUserName(soapModel.getUserName());
        model.setCreateDate(soapModel.getCreateDate());
        model.setModifiedDate(soapModel.getModifiedDate());
        model.setName(soapModel.getName());
        model.setDescription(soapModel.getDescription());
        model.setScript(soapModel.getScript());
        model.setTemplateParam(soapModel.getTemplateParam());

        return model;
    }

    /**
     * Converts the soap model instances into normal model instances.
     *
     * @param soapModels the soap model instances to convert
     * @return the normal model instances
     */
    public static List<ChartTemplate> toModels(ChartTemplateSoap[] soapModels) {
        if (soapModels == null) {
            return null;
        }

        List<ChartTemplate> models = new ArrayList<ChartTemplate>(soapModels.length);

        for (ChartTemplateSoap soapModel : soapModels) {
            models.add(toModel(soapModel));
        }

        return models;
    }

    @Override
    public long getPrimaryKey() {
        return _chartTemplateId;
    }

    @Override
    public void setPrimaryKey(long primaryKey) {
        setChartTemplateId(primaryKey);
    }

    @Override
    public Serializable getPrimaryKeyObj() {
        return _chartTemplateId;
    }

    @Override
    public void setPrimaryKeyObj(Serializable primaryKeyObj) {
        setPrimaryKey(((Long) primaryKeyObj).longValue());
    }

    @Override
    public Class<?> getModelClass() {
        return ChartTemplate.class;
    }

    @Override
    public String getModelClassName() {
        return ChartTemplate.class.getName();
    }

    @Override
    public Map<String, Object> getModelAttributes() {
        Map<String, Object> attributes = new HashMap<String, Object>();

        attributes.put("uuid", getUuid());
        attributes.put("chartTemplateId", getChartTemplateId());
        attributes.put("groupId", getGroupId());
        attributes.put("companyId", getCompanyId());
        attributes.put("userId", getUserId());
        attributes.put("userName", getUserName());
        attributes.put("createDate", getCreateDate());
        attributes.put("modifiedDate", getModifiedDate());
        attributes.put("name", getName());
        attributes.put("description", getDescription());
        attributes.put("script", getScript());
        attributes.put("templateParam", getTemplateParam());

        return attributes;
    }

    @Override
    public void setModelAttributes(Map<String, Object> attributes) {
        String uuid = (String) attributes.get("uuid");

        if (uuid != null) {
            setUuid(uuid);
        }

        Long chartTemplateId = (Long) attributes.get("chartTemplateId");

        if (chartTemplateId != null) {
            setChartTemplateId(chartTemplateId);
        }

        Long groupId = (Long) attributes.get("groupId");

        if (groupId != null) {
            setGroupId(groupId);
        }

        Long companyId = (Long) attributes.get("companyId");

        if (companyId != null) {
            setCompanyId(companyId);
        }

        Long userId = (Long) attributes.get("userId");

        if (userId != null) {
            setUserId(userId);
        }

        String userName = (String) attributes.get("userName");

        if (userName != null) {
            setUserName(userName);
        }

        Date createDate = (Date) attributes.get("createDate");

        if (createDate != null) {
            setCreateDate(createDate);
        }

        Date modifiedDate = (Date) attributes.get("modifiedDate");

        if (modifiedDate != null) {
            setModifiedDate(modifiedDate);
        }

        String name = (String) attributes.get("name");

        if (name != null) {
            setName(name);
        }

        String description = (String) attributes.get("description");

        if (description != null) {
            setDescription(description);
        }

        String script = (String) attributes.get("script");

        if (script != null) {
            setScript(script);
        }

        String templateParam = (String) attributes.get("templateParam");

        if (templateParam != null) {
            setTemplateParam(templateParam);
        }
    }

    @JSON
    @Override
    public String getUuid() {
        if (_uuid == null) {
            return StringPool.BLANK;
        } else {
            return _uuid;
        }
    }

    @Override
    public void setUuid(String uuid) {
        if (_originalUuid == null) {
            _originalUuid = _uuid;
        }

        _uuid = uuid;
    }

    public String getOriginalUuid() {
        return GetterUtil.getString(_originalUuid);
    }

    @JSON
    @Override
    public long getChartTemplateId() {
        return _chartTemplateId;
    }

    @Override
    public void setChartTemplateId(long chartTemplateId) {
        _chartTemplateId = chartTemplateId;
    }

    @JSON
    @Override
    public long getGroupId() {
        return _groupId;
    }

    @Override
    public void setGroupId(long groupId) {
        _columnBitmask |= GROUPID_COLUMN_BITMASK;

        if (!_setOriginalGroupId) {
            _setOriginalGroupId = true;

            _originalGroupId = _groupId;
        }

        _groupId = groupId;
    }

    public long getOriginalGroupId() {
        return _originalGroupId;
    }

    @JSON
    @Override
    public long getCompanyId() {
        return _companyId;
    }

    @Override
    public void setCompanyId(long companyId) {
        _columnBitmask |= COMPANYID_COLUMN_BITMASK;

        if (!_setOriginalCompanyId) {
            _setOriginalCompanyId = true;

            _originalCompanyId = _companyId;
        }

        _companyId = companyId;
    }

    public long getOriginalCompanyId() {
        return _originalCompanyId;
    }

    @JSON
    @Override
    public long getUserId() {
        return _userId;
    }

    @Override
    public void setUserId(long userId) {
        _userId = userId;
    }

    @Override
    public String getUserUuid() throws SystemException {
        return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
    }

    @Override
    public void setUserUuid(String userUuid) {
        _userUuid = userUuid;
    }

    @JSON
    @Override
    public String getUserName() {
        if (_userName == null) {
            return StringPool.BLANK;
        } else {
            return _userName;
        }
    }

    @Override
    public void setUserName(String userName) {
        _userName = userName;
    }

    @JSON
    @Override
    public Date getCreateDate() {
        return _createDate;
    }

    @Override
    public void setCreateDate(Date createDate) {
        _columnBitmask = -1L;

        _createDate = createDate;
    }

    @JSON
    @Override
    public Date getModifiedDate() {
        return _modifiedDate;
    }

    @Override
    public void setModifiedDate(Date modifiedDate) {
        _modifiedDate = modifiedDate;
    }

    @JSON
    @Override
    public String getName() {
        if (_name == null) {
            return StringPool.BLANK;
        } else {
            return _name;
        }
    }

    @Override
    public void setName(String name) {
        _name = name;
    }

    @JSON
    @Override
    public String getDescription() {
        if (_description == null) {
            return StringPool.BLANK;
        } else {
            return _description;
        }
    }

    @Override
    public void setDescription(String description) {
        _description = description;
    }

    @JSON
    @Override
    public String getScript() {
        if (_script == null) {
            return StringPool.BLANK;
        } else {
            return _script;
        }
    }

    @Override
    public void setScript(String script) {
        _script = script;
    }

    @JSON
    @Override
    public String getTemplateParam() {
        if (_templateParam == null) {
            return StringPool.BLANK;
        } else {
            return _templateParam;
        }
    }

    @Override
    public void setTemplateParam(String templateParam) {
        _templateParam = templateParam;
    }

    @Override
    public StagedModelType getStagedModelType() {
        return new StagedModelType(PortalUtil.getClassNameId(
                ChartTemplate.class.getName()));
    }

    public long getColumnBitmask() {
        return _columnBitmask;
    }

    @Override
    public ExpandoBridge getExpandoBridge() {
        return ExpandoBridgeFactoryUtil.getExpandoBridge(getCompanyId(),
            ChartTemplate.class.getName(), getPrimaryKey());
    }

    @Override
    public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
        ExpandoBridge expandoBridge = getExpandoBridge();

        expandoBridge.setAttributes(serviceContext);
    }

    @Override
    public ChartTemplate toEscapedModel() {
        if (_escapedModel == null) {
            _escapedModel = (ChartTemplate) ProxyUtil.newProxyInstance(_classLoader,
                    _escapedModelInterfaces, new AutoEscapeBeanHandler(this));
        }

        return _escapedModel;
    }

    @Override
    public Object clone() {
        ChartTemplateImpl chartTemplateImpl = new ChartTemplateImpl();

        chartTemplateImpl.setUuid(getUuid());
        chartTemplateImpl.setChartTemplateId(getChartTemplateId());
        chartTemplateImpl.setGroupId(getGroupId());
        chartTemplateImpl.setCompanyId(getCompanyId());
        chartTemplateImpl.setUserId(getUserId());
        chartTemplateImpl.setUserName(getUserName());
        chartTemplateImpl.setCreateDate(getCreateDate());
        chartTemplateImpl.setModifiedDate(getModifiedDate());
        chartTemplateImpl.setName(getName());
        chartTemplateImpl.setDescription(getDescription());
        chartTemplateImpl.setScript(getScript());
        chartTemplateImpl.setTemplateParam(getTemplateParam());

        chartTemplateImpl.resetOriginalValues();

        return chartTemplateImpl;
    }

    @Override
    public int compareTo(ChartTemplate chartTemplate) {
        int value = 0;

        value = DateUtil.compareTo(getCreateDate(),
                chartTemplate.getCreateDate());

        value = value * -1;

        if (value != 0) {
            return value;
        }

        return 0;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }

        if (!(obj instanceof ChartTemplate)) {
            return false;
        }

        ChartTemplate chartTemplate = (ChartTemplate) obj;

        long primaryKey = chartTemplate.getPrimaryKey();

        if (getPrimaryKey() == primaryKey) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public int hashCode() {
        return (int) getPrimaryKey();
    }

    @Override
    public void resetOriginalValues() {
        ChartTemplateModelImpl chartTemplateModelImpl = this;

        chartTemplateModelImpl._originalUuid = chartTemplateModelImpl._uuid;

        chartTemplateModelImpl._originalGroupId = chartTemplateModelImpl._groupId;

        chartTemplateModelImpl._setOriginalGroupId = false;

        chartTemplateModelImpl._originalCompanyId = chartTemplateModelImpl._companyId;

        chartTemplateModelImpl._setOriginalCompanyId = false;

        chartTemplateModelImpl._columnBitmask = 0;
    }

    @Override
    public CacheModel<ChartTemplate> toCacheModel() {
        ChartTemplateCacheModel chartTemplateCacheModel = new ChartTemplateCacheModel();

        chartTemplateCacheModel.uuid = getUuid();

        String uuid = chartTemplateCacheModel.uuid;

        if ((uuid != null) && (uuid.length() == 0)) {
            chartTemplateCacheModel.uuid = null;
        }

        chartTemplateCacheModel.chartTemplateId = getChartTemplateId();

        chartTemplateCacheModel.groupId = getGroupId();

        chartTemplateCacheModel.companyId = getCompanyId();

        chartTemplateCacheModel.userId = getUserId();

        chartTemplateCacheModel.userName = getUserName();

        String userName = chartTemplateCacheModel.userName;

        if ((userName != null) && (userName.length() == 0)) {
            chartTemplateCacheModel.userName = null;
        }

        Date createDate = getCreateDate();

        if (createDate != null) {
            chartTemplateCacheModel.createDate = createDate.getTime();
        } else {
            chartTemplateCacheModel.createDate = Long.MIN_VALUE;
        }

        Date modifiedDate = getModifiedDate();

        if (modifiedDate != null) {
            chartTemplateCacheModel.modifiedDate = modifiedDate.getTime();
        } else {
            chartTemplateCacheModel.modifiedDate = Long.MIN_VALUE;
        }

        chartTemplateCacheModel.name = getName();

        String name = chartTemplateCacheModel.name;

        if ((name != null) && (name.length() == 0)) {
            chartTemplateCacheModel.name = null;
        }

        chartTemplateCacheModel.description = getDescription();

        String description = chartTemplateCacheModel.description;

        if ((description != null) && (description.length() == 0)) {
            chartTemplateCacheModel.description = null;
        }

        chartTemplateCacheModel.script = getScript();

        String script = chartTemplateCacheModel.script;

        if ((script != null) && (script.length() == 0)) {
            chartTemplateCacheModel.script = null;
        }

        chartTemplateCacheModel.templateParam = getTemplateParam();

        String templateParam = chartTemplateCacheModel.templateParam;

        if ((templateParam != null) && (templateParam.length() == 0)) {
            chartTemplateCacheModel.templateParam = null;
        }

        return chartTemplateCacheModel;
    }

    @Override
    public String toString() {
        StringBundler sb = new StringBundler(25);

        sb.append("{uuid=");
        sb.append(getUuid());
        sb.append(", chartTemplateId=");
        sb.append(getChartTemplateId());
        sb.append(", groupId=");
        sb.append(getGroupId());
        sb.append(", companyId=");
        sb.append(getCompanyId());
        sb.append(", userId=");
        sb.append(getUserId());
        sb.append(", userName=");
        sb.append(getUserName());
        sb.append(", createDate=");
        sb.append(getCreateDate());
        sb.append(", modifiedDate=");
        sb.append(getModifiedDate());
        sb.append(", name=");
        sb.append(getName());
        sb.append(", description=");
        sb.append(getDescription());
        sb.append(", script=");
        sb.append(getScript());
        sb.append(", templateParam=");
        sb.append(getTemplateParam());
        sb.append("}");

        return sb.toString();
    }

    @Override
    public String toXmlString() {
        StringBundler sb = new StringBundler(40);

        sb.append("<model><model-name>");
        sb.append("cn.shuto.liferay.plugin.chart.service.model.ChartTemplate");
        sb.append("</model-name>");

        sb.append(
            "<column><column-name>uuid</column-name><column-value><![CDATA[");
        sb.append(getUuid());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>chartTemplateId</column-name><column-value><![CDATA[");
        sb.append(getChartTemplateId());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>groupId</column-name><column-value><![CDATA[");
        sb.append(getGroupId());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>companyId</column-name><column-value><![CDATA[");
        sb.append(getCompanyId());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>userId</column-name><column-value><![CDATA[");
        sb.append(getUserId());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>userName</column-name><column-value><![CDATA[");
        sb.append(getUserName());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>createDate</column-name><column-value><![CDATA[");
        sb.append(getCreateDate());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>modifiedDate</column-name><column-value><![CDATA[");
        sb.append(getModifiedDate());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>name</column-name><column-value><![CDATA[");
        sb.append(getName());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>description</column-name><column-value><![CDATA[");
        sb.append(getDescription());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>script</column-name><column-value><![CDATA[");
        sb.append(getScript());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>templateParam</column-name><column-value><![CDATA[");
        sb.append(getTemplateParam());
        sb.append("]]></column-value></column>");

        sb.append("</model>");

        return sb.toString();
    }
}
